import sys

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, \
    QCheckBox, QSlider, QProgressBar, QComboBox

'''
主要用于省市选择联动
QComboBox
addItem 
combo1.setEditable(True)  # 可编辑
combo1.activated[int].connect(self.mySelect1) / combo1.activated[str].connect(self.mySelect1)
self.combo2.clear()  # 清除上次的addItem项目
'''


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        myFrame1 = QFrame(self)
        myFrame1.move(50, 50)
        lbl1 = QLabel('省', myFrame1)
        lbl1.move(0, 3)
        combo1 = QComboBox(myFrame1)
        combo1.move(20, 0)
        combo1.addItem('选择省份')
        combo1.addItem('江苏')
        combo1.addItem('浙江')
        combo1.addItem('江西')
        # combo1.setEditable(True)  # 可编辑
        # combo1.editTextChanged()
        combo1.activated[int].connect(self.mySelect1)

        lbl2 = QLabel('市', myFrame1)
        lbl2.move(105, 3)
        self.combo2 = QComboBox(myFrame1)
        self.combo2.move(120, 0)

        self.show()

    def mySelect1(self, s1):
        # print(s1)
        self.combo2.clear()  # 清除上次的addItem项目
        self.combo2.addItem('选择市')
        if s1 == 1:
            self.combo2.addItem('南京')
            self.combo2.addItem('苏州')
            self.combo2.addItem('南通')
        elif s1 == 2:
            self.combo2.addItem('杭州')
            self.combo2.addItem('宁波')
            self.combo2.addItem('温州')
        elif s1 == 3:
            self.combo2.addItem('南昌')
            self.combo2.addItem('宜春')
            self.combo2.addItem('鄱阳湖')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
